<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	小程序粉丝管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['name']){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$fields=array('id','name','picurl','paixu','codetext','codebg','codecolor','typename','isshow','coderight','codebottom');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('jy_kefu_group',$params,array($pindex,$psize),$total,$fields);
	if($list){
		foreach($list as &$row){
			$row['url']=custom_url(array('jy_kefu/home/',array('groupid'=>$row['id'])),true);;
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'客服组列表'),
		),
		'list'=>array('data'=>'list','delall'=>false,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'name','title'=>'名称','type'=>'string'),
			array('name'=>'picurl','title'=>'logo','type'=>'image'),
			array('name'=>'url','title'=>'客服组链接','type'=>'string'),
		),'action'=>array(
			//array('type'=>'modal','op'=>'code','title'=>'嵌入代码'),
		)),
		'search_one'=>array('name'=>'name','add_op'=>'edit')
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kefu_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'客服组详情',
		'tabs'=>array(
			array('op'=>'list','title'=>'客服组列表'),
			array('op'=>'detail','title'=>'客服组详情'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'名称','name'=>'name', 'help'=>'' ),
			array('type'=>'image','title'=>'logo','name'=>'picurl', 'help'=>'' ),
			array('type'=>'switch','title'=>'是否显示','name'=>'isshow','help'=>'' ),
			array('type'=>'string','title'=>'排序','name'=>'paixu' , 'help'=>''),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array(
		'name'=>trim($post['name']),
		'picurl'=>trim($post['picurl']),
		'isshow'=>intval($post['isshow']),
		'paixu'=>intval($post['paixu']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('jy_kefu_group',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_kefu_group',$data);
	}
	exi('保存成功！','','list');
}
?>